const Axios = require('axios')

const baseUrl = ''
module.exports = function (ctx, next) {

    const path = ctx.path
    const query = ctx.query
    const session = ctx.session
    const params = {
        ...query,
        ...ctx.response.body
    }

    Axios(`${baseUrl}${path}`, {
        data: params,
        method: ctx.method,
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    }).then(res => {
        if (res.status === 200) {
            ctx.body = res.data
        } else {
            res.status = 500
            ctx.body = res.data
        }
    }).then(err => {
        res.status = 500
        if (err.response) {
            res.body = err.response.data
        } else {
            res.body = {
                success: false,
                msg: '未知错误'
            }
        }
    })
}
